# -*- coding: utf-8 -*-
#
# Copyright 2009 Vanderbilt University
# 
# Licensed under the Apache License, Version 2.0 (the "License"); 
# you may not use this file except in compliance with the License. 
# You may obtain a copy of the License at 
# 
#     http://www.apache.org/licenses/LICENSE-2.0 
# 
# Unless required by applicable law or agreed to in writing, software 
# distributed under the License is distributed on an "AS IS" BASIS, 
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
# See the License for the specific language governing permissions and 
# limitations under the License. 
"""

.. moduleauthor:: John Paulett <john.paulett -at- vanderbilt.edu>
"""
def monte_carlo(graph, max_trial_size, prune_filter, metric):
    #TODO remove filter size
    #rgraphs = []
    metric_values = []
    stdevs = {}
    means = {}
    for i in xrange(0, max_trial_size):
        r = hornet.randomize(graph)
        r = hornet.prune(r, prune_filter, 5)
        #rgraphs.append(r)
        metric_values.append(metric(r))

        if i >= 2:
            stdevs[i] = numpy.std(metric_values)
            means[i] = numpy.mean(metric_values)
    
    k = stdevs.keys()
    coef_variation = numpy.array(stdevs.values()) / numpy.array(means.values())
    pylab.subplot(211)
    pylab.plot(k, coef_variation, '.')
    pylab.xlabel('Sample Size')
    pylab.ylabel('Coefficient of Variation')
    pylab.subplot(212)
    pylab.plot(k[1:], numpy.abs(numpy.diff(coef_variation)), '.')
    pylab.xlabel('Sample Size')
    pylab.ylabel('|Change of Coefficient of Variation|')
    pylab.show()
